package com.example.workrecord.util;


import com.example.workrecord.exption.CheckException;

import java.util.List;
import java.util.Map;

/**
 *
 */
public class CheckUtil {

    /**
     * 判断是否为空
     * @param obj
     * @return
     */
    public static boolean isEmpty(Object obj) {
        if (obj instanceof List){
            if (checkList((List)obj)){
                return true;
            }
        }
        if (obj instanceof Map){
            if (checkMap((Map)obj)){
                return true;
            }
        }
        if (obj == null || obj.equals("")) {
            return true;
        }

        return false;
    }
    public static void checkNull(Object obj, String msg) {
        if (obj == null) {
            throw new CheckException(msg);
        }
        if (obj instanceof List){
            if (checkList((List)obj)){
                throw new CheckException(msg);
            }
        }
        if (obj instanceof Map){
            if (checkMap((Map)obj)){
                throw new CheckException(msg);
            }
        }
    }
    public static Boolean checkList(List list) {
        if (list==null||list.size()<=0) {
            return  true;
        }
        return  false;
    }
    public static Boolean checkMap(Map map) {
        if (map==null||map.size()<=0) {
            return  true;
        }
        return  false;
    }
}
